package com.qf.config;

import com.qf.utils.BCryptPasswordEncoder;
import com.qf.utils.JwtUtils;
import com.qf.utils.PasswordEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

/**
 * 作者；雷明旭
 * 时间；2021/11/210:14
 * bug退散bug退散bug退散
 */
@Configuration
public class AppConfig {

    //添加后台系统密码校验
    @Bean
    public PasswordEncoder passwordEncoder (){
       return new BCryptPasswordEncoder();
    }

    @Bean
    public JwtUtils jwtUtils(AppProperties appProperties){
        return new JwtUtils(
                new SecretKeySpec(Base64.getDecoder().decode(appProperties.getJwt().getKey()), "HmacSHA512"),
                new SecretKeySpec(Base64.getDecoder().decode(appProperties.getJwt().getRefreshKey()), "HmacSHA512"),
                appProperties.getJwt().getAccessJwtExpire(),
                appProperties.getJwt().getRefreshJwtExpire()

        );
    }

}
